﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Web;

namespace simpleHotel.Web
{
    public class HotelHelper
    {
        public static string GetHotelFolder(string hotelId) {
            var rootFolder = HttpContext.Current.Server.MapPath("~/ImageData");
            var folder = rootFolder.Trim('\\') + "\\" + hotelId;
            if (Directory.Exists(folder)) {
                return folder;
            }
            try
            {
                Directory.CreateDirectory(folder);
                Directory.CreateDirectory(folder + "\\Image");
                Directory.CreateDirectory(folder + "\\SmallImages"); 
                return folder;
            }
            catch (Exception ex) { 
                //write log,
                return string.Empty;
            }
        }

        public static string GetSmallImagesFolder(string hotelId)
        {
            var rootFolder = HttpContext.Current.Server.MapPath("~/ImageData");
            var folder = rootFolder.Trim('\\') + "\\" + hotelId;
            if (Directory.Exists(folder))
            {
                if (Directory.Exists(folder + "\\SmallImages"))
                    return folder + "\\SmallImages";
                try
                {
                    Directory.CreateDirectory(folder + "\\SmallImages");
                    return folder + "\\SmallImages";
                }
                catch {
                    return string.Empty;
                }
            }
            try
            {
                Directory.CreateDirectory(folder);
                Directory.CreateDirectory(folder + "\\Image");
                Directory.CreateDirectory(folder + "\\SmallImages");

                return folder + "\\SmallImages";
            }
            catch (Exception ex)
            {
                //write log,
                return string.Empty;
            }
        }

        public static string GetImageFolder(string hotelId)
        {
            var rootFolder = HttpContext.Current.Server.MapPath("~/ImageData");
            var folder = rootFolder.Trim('\\') + "\\" + hotelId;
            if (Directory.Exists(folder))
            {
                if (Directory.Exists(folder + "\\Image"))
                    return folder + "\\Image";
                try
                {
                    Directory.CreateDirectory(folder + "\\Image");
                    return folder + "\\Image";
                }
                catch
                {
                    return string.Empty;
                }
            }
            try
            {
                Directory.CreateDirectory(folder);
                Directory.CreateDirectory(folder + "\\Image");
                Directory.CreateDirectory(folder + "\\SmallImages");

                return folder + "\\Image";
            }
            catch (Exception ex)
            {
                //write log,
                return string.Empty;
            }
        }
    }
}